* I moved this data cleaning code to the top (not sure why it was below. I cringe when I look at this code now! Haha)

* I broke this .do file out into three sections. One for the intial analyses we have in the paper. One for only Blacks excluded and another for all races excluded.



*****************************************************************************
************** Our current analysis ***************
*****************************************************************************
clear
cd "~/Box Sync/Religion, Racial Resentment, and Punitive Attitudes Manuscript Revisions/"
use punitydata_final.dta

* ANALYSIS
tab region4
gen midwest= region4_x
recode midwest 1=1 2/4=0

gen northeast= region4_x
recode northeast 1=0 2=1 3/4=0

gen west = region4_x
recode west 1/3=0 4=1

*Ologit Model 1
ologit revracial_resentment_x i.reltrad, or

*Ologit Model 2 *** This table is missing the OR's for racial resentment and the coefficients are slightly off
ologit revracial_resentment_x i.reltrad trump gender_final income_x ed2 ed3 ed4 age partyid7_x attend midwest northeast west, or

***Logit Model 1
logit binary_justice_ideology i.reltrad, or

***Logit Model 2
logit binary_justice_ideology i.reltrad revracial_resentment_x, or

***Logit Model 3
logit binary_justice_ideology i.reltrad revracial_resentment_x trump gender_final income_x ed2 ed3 ed4 age partyid7_x attend midwest northeast west, or

*** Mediation tests
medeff (regress revracial_resentment_x other_religion jewish catholic mainline_protestant_new mormon evangelical_new black_protestant_new attend trump gender_final black hispanic other_race income_x ed2 ed3 ed4 age partyid7_x midwest northeast west) (logit binary_justice_ideology  other_religion jewish catholic mainline_protestant_new mormon evangelical_new black_protestant_new revracial_resentment_x attend trump gender_final black hispanic other_race income_x ed2 ed3 ed4 age partyid7_x midwest northeast west), treat (mainline_protestant_new) mediate (revracial_resentment_x) sims (500)
********************************************************************************************************



*****************************************************************************
************** Removing black respondents ***************
*****************************************************************************
clear
cd "~/Box Sync/Religion, Racial Resentment, and Punitive Attitudes Manuscript Revisions/"
use punitydata_final.dta

* Do we keep the same codings here or 

* ANALYSIS
drop if racethnicity == "Black, non-Hispanic"

encode religion, generate(religion_x1)
gen jewish1=0
replace jewish1=1 if religion=="Jewish (Judaism)"

gen catholic1=0
replace catholic1=1 if religion=="Roman Catholic (Catholic)"

gen mormon1=0
replace mormon1=1 if religion=="Mormon (Church of Jesus Christ of Latter-day Saints/LDS)"

gen other_religion1=0
replace other_religion1=1 if religion=="Buddhist"
replace other_religion1=1 if religion=="Hindu"
replace other_religion1=1 if religion=="Muslim (Islam)"
replace other_religion1=1 if religion=="Orthodox (Greek, Russian, or some other orthodox church)"
replace other_religion1=1 if religion=="Unitarian (Universalist)"

gen secular_new1 = 0
replace secular_new1=1 if religion_x1== 1
replace secular_new1=1 if religion_x1== 2
replace secular_new1=1 if religion_x1== 4
replace secular_new1=1 if religion_x1== 10
tab secular_new1

gen mainline_protestant_new1=0
replace mainline_protestant_new1=1 if religion_x1==12 & born_again_x==0
replace mainline_protestant_new1=1 if religion_x1==7 & born_again_x==0
tab mainline_protestant_new1

gen evangelical_new1=0
replace evangelical_new1=1 if religion_x1==7 &born_again_x==1
tab evangelical_new1
replace evangelical_new1=1 if religion_x1==12 & born_again_x==1
tab evangelical_new1

gen reltrad_noblack =.
replace reltrad_noblack=1 if secular_new1==1
replace reltrad_noblack=2 if other_religion1==1
replace reltrad_noblack=3 if jewish1==1
replace reltrad_noblack=4 if catholic1==1
replace reltrad_noblack=5 if mormon1==1
replace reltrad_noblack=6 if mainline_protestant_new1==1
replace reltrad_noblack=7 if evangelical_new1==1
tab reltrad_noblack

tab region4
gen midwest= region4_x
recode midwest 1=1 2/4=0

gen northeast= region4_x
recode northeast 1=0 2=1 3/4=0

gen west = region4_x
recode west 1/3=0 4=1

* I am thinking we need to control for race now since it isn't baked into the RELTRAD measure anymore
*The race dummies are hispanic and other_race with white omitted as the baseline

*Ologit Model 1
ologit revracial_resentment_x i.reltrad_noblack, or

*Ologit Model 2 *** This table is missing the OR's for racial resentment and the coefficients are slightly off
ologit revracial_resentment_x i.reltrad_noblack trump gender_final income_x ed2 ed3 ed4 age partyid7_x attend midwest northeast west hispanic other_race, or

***Logit Model 1
logit binary_justice_ideology i.reltrad_noblack, or

***Logit Model 2
logit binary_justice_ideology i.reltrad_noblack revracial_resentment_x, or

***Logit Model 3
logit binary_justice_ideology i.reltrad_noblack revracial_resentment_x trump gender_final income_x ed2 ed3 ed4 age partyid7_x attend midwest northeast west hispanic other_race, or

*** Mediation tests
medeff (regress revracial_resentment_x other_religion1 jewish1 catholic1 mainline_protestant_new1 mormon1 evangelical_new1 attend trump gender_final hispanic other_race income_x ed2 ed3 ed4 age partyid7_x midwest northeast west) (logit binary_justice_ideology  other_religion jewish catholic mainline_protestant_new mormon evangelical_new revracial_resentment_x attend trump gender_final hispanic other_race income_x ed2 ed3 ed4 age partyid7_x midwest northeast west), treat (mainline_protestant_new1) mediate (revracial_resentment_x) sims (500)
********************************************************************************************************


*****************************************************************************
************** Removing all non-white respondents ***************
*****************************************************************************
clear
cd "~/Box Sync/Religion, Racial Resentment, and Punitive Attitudes Manuscript Revisions/"
use punitydata_final.dta

* Do we keep the same codings here or 

* ANALYSIS
drop if racethnicity != "White, non-Hispanic"

encode religion, generate(religion_x2)
gen jewish2=0
replace jewish2=1 if religion=="Jewish (Judaism)"

gen catholic2=0
replace catholic2=1 if religion=="Roman Catholic (Catholic)"

gen mormon2=0
replace mormon2=1 if religion=="Mormon (Church of Jesus Christ of Latter-day Saints/LDS)"

gen other_religion2=0
replace other_religion2=1 if religion=="Buddhist"
replace other_religion2=1 if religion=="Hindu"
replace other_religion2=1 if religion=="Muslim (Islam)"
replace other_religion2=1 if religion=="Orthodox (Greek, Russian, or some other orthodox church)"
replace other_religion2=1 if religion=="Unitarian (Universalist)"

gen secular_new2 = 0
replace secular_new2=1 if religion_x2== 1
replace secular_new2=1 if religion_x2== 2
replace secular_new2=1 if religion_x2== 4
replace secular_new2=1 if religion_x2== 10
tab secular_new2

gen mainline_protestant_new2=0
replace mainline_protestant_new2=1 if religion_x2==12 & born_again_x==0
replace mainline_protestant_new2=1 if religion_x2==7 & born_again_x==0
tab mainline_protestant_new2

gen evangelical_new2=0
replace evangelical_new2=1 if religion_x2==7 &born_again_x==1
tab evangelical_new2
replace evangelical_new2=1 if religion_x2==12 & born_again_x==1
tab evangelical_new2

gen reltrad_allwhite =.
replace reltrad_allwhite=1 if secular_new2==1
replace reltrad_allwhite=2 if other_religion2==1
replace reltrad_allwhite=3 if jewish2==1
replace reltrad_allwhite=4 if catholic2==1
replace reltrad_allwhite=5 if mormon2==1
replace reltrad_allwhite=6 if mainline_protestant_new2==1
replace reltrad_allwhite=7 if evangelical_new2==1
tab reltrad_allwhite

tab region4
gen midwest= region4_x
recode midwest 1=1 2/4=0

gen northeast= region4_x
recode northeast 1=0 2=1 3/4=0

gen west = region4_x
recode west 1/3=0 4=1

* I am thinking we need to control for race now since it isn't baked into the RELTRAD measure anymore
*The race dummies are hispanic and other_race with white omitted as the baseline

*Ologit Model 1
ologit revracial_resentment_x i.reltrad_allwhite, or

*Ologit Model 2 *** This table is missing the OR's for racial resentment and the coefficients are slightly off
ologit revracial_resentment_x i.reltrad_allwhite trump gender_final income_x ed2 ed3 ed4 age partyid7_x attend midwest northeast west, or

***Logit Model 1
logit binary_justice_ideology i.reltrad_allwhite, or

***Logit Model 2
logit binary_justice_ideology i.reltrad_allwhite revracial_resentment_x, or

***Logit Model 3
logit binary_justice_ideology i.reltrad_allwhite revracial_resentment_x trump gender_final income_x ed2 ed3 ed4 age partyid7_x attend midwest northeast west, or

*** Mediation tests
medeff (regress revracial_resentment_x other_religion2 jewish2 catholic2 mainline_protestant_new2 mormon2 evangelical_new2 attend trump gender_final income_x ed2 ed3 ed4 age partyid7_x midwest northeast west) (logit binary_justice_ideology other_religion2 jewish2 catholic2 mainline_protestant_new2 mormon2 evangelical_new2 revracial_resentment_x attend trump gender_final income_x ed2 ed3 ed4 age partyid7_x midwest northeast west), treat (mainline_protestant_new2) mediate (revracial_resentment_x) sims (500)
********************************************************************************************************










*****************************************************************************
************** Code used to previously clean variables ***************
*****************************************************************************

rename q14 justice_ideology
gen justice_ideology_x=0
replace justice_ideology_x=1 if justice_ideology=="Enforcement, such as putting more police officers on the streets"
replace justice_ideology_x=2 if justice_ideology=="Punishment, such as longer sentences and more prisons"
replace justice_ideology_x=3 if justice_ideology=="Rehabilitation, such as job training and education for offenders"
replace justice_ideology_x=4 if justice_ideology=="Prevention, such as youth education programs"
replace justice_ideology_x=. if justice_ideology=="Don't know?/Refused"
tab justice_ideology_x
***1 enforcement, 2 punishment, 3 rehab, 4 prevention

gen binary_justice_ideology=.
replace binary_justice_ideology=1 if justice_ideology_x==1
replace binary_justice_ideology=1 if justice_ideology_x==2
replace binary_justice_ideology=0 if justice_ideology_x==3
replace binary_justice_ideology=0 if justice_ideology_x==4
tab binary_justice_ideology

*This is all I needed to do with the region variable
encode region4, generate(region4_x)

tab region4
gen midwest= region4_x
recode midwest 1=1 2/4=0

gen northeast= region4_x
recode northeast 1=0 2=1 3/4=0

gen west = region4_x
recode west 1/3=0 4=1

gen church_attendance_x =0
replace church_attendance_x=1 if church_attendance=="More than once a week"
replace church_attendance_x=2 if church_attendance=="Once a week"
replace church_attendance_x=3 if church_attendance=="Once or twice a month"
replace church_attendance_x=4 if church_attendance=="A few times a year"
replace church_attendance_x=5 if church_attendance=="Seldom"
replace church_attendance_x=6 if church_attendance=="Never"
replace church_attendance_x=. if church_attendance=="Don't know?/Refused"
tab church_attendance_x
revrs church_attendance_x
gen attend = revchurch_attendance_x

rename q16e racial_resentment
gen racial_resentment_x=0
replace racial_resentment_x=1 if racial_resentment=="Completely agree"
replace racial_resentment_x=2 if racial_resentment=="Mostly agree"
replace racial_resentment_x=3 if racial_resentment=="Mostly disagree"
replace racial_resentment_x=4 if racial_resentment=="Completely disagree"
replace racial_resentment_x=. if racial_resentment=="Don't know?/Refused"
tab racial_resentment_x
revrs racial_resentment_x
fre revracial_resentment_x

tab partyid7
gen partyid7_x=0
replace partyid7_x=1 if partyid7=="Strong Democrat"
replace partyid7_x=2 if partyid7=="Moderate Democrat"
replace partyid7_x=3 if partyid7=="Lean Democrat"
replace partyid7_x=4 if partyid7=="Don't Lean/Independent/None"
replace partyid7_x=4 if partyid7=="Unknown"
replace partyid7_x=5 if partyid7=="Lean Republican"
replace partyid7_x=6 if partyid7=="Moderate Republican"
replace partyid7_x=7 if partyid7=="Strong Republican"
tab partyid7_x

gen other_religionXracial_resentment= other_religion*cc_racial_resentment
gen jewishXracial= jewish*cc_racial_resentment
gen catholicXracial= catholic*cc_racial_resentment
gen mainline_protestant_newXracial= mainline_protestant_new*cc_racial_resentment
gen evangelical_newXracial= evangelical_new*cc_racial_resentment
gen black_protestant_newXracial= black_protestant_new*cc_racial_resentment

***Age is already coded appropriately

replace gender_x=1 if gender=="Male"
replace gender_x=0 if gender=="Female"
gen gender_final = .
replace gender_final = 1 if gender == "Female"
replace gender_final = 0 if gender == "Male"
tab gender_final

tab educ4
gen education=0
replace education=1 if educ4=="BA or above"
replace education=2 if educ4=="Some college"
replace education=3 if educ4=="HS graduate or equivalent"
replace education=4 if educ4=="No HS diploma"
tab education
gen ed1 = 0
replace ed1 = 1 if education == 4
tab ed1
gen ed2 = 0
replace ed2 = 1 if education == 3
tab ed2
gen ed3 = 0
replace ed3 = 1 if education ==2
tab ed3
gen ed4 = 0
replace ed4 = 1 if education == 1
tab ed4

tab income
gen income_x=0
replace income_x=1 if income=="Less than $5,000"
replace income_x=1 if income=="$5,000 to $9,999"
replace income_x=1 if income=="$10,000 to $14,999"
replace income_x=1 if income=="$15,000 to $19,999"
replace income_x=1 if income=="$20,000 to $24,999"
replace income_x=2 if income =="$25,000 to $29,999"
replace income_x=2 if income =="$30,000 to $34,999"
replace income_x=2 if income =="$35,000 to $39,999"
replace income_x=2 if income =="$40,000 to $49,999"
replace income_x=3 if income=="$50,000 to $59,999"
replace income_x=3 if income=="$60,000 to $74,999"
replace income_x=4 if income=="$75,000 to $84,999"
replace income_x=4 if income=="$85,000 to $99,999"
replace income_x=5 if income=="$100,000 to $124,999"
replace income_x=5 if income=="$125,000 to $149,999"
replace income_x=6 if income=="$150,000 to $174,999"
replace income_x=6 if income=="$175,000 to $199,999"
replace income_x=7 if income=="$200,000 or more"
tab income_x

gen trump=0
replace trump=1 if q24=="Donald Trump, the Republican"

gen white=0
replace white=1 if racethnicity=="White, non-Hispanic"
gen asian=0
replace asian=1 if racethnicity=="Asian, non-Hispanic"
gen black=0
replace black=1 if racethnicity=="Black, non-Hispanic"
gen hispanic=0
replace hispanic=1 if racethnicity=="Hispanic"
gen other_race=0
replace other_race=1 if racethnicity=="Other, non-Hispanic"
replace other_race=1 if racethnicity=="2+, non-Hispanic"
replace other_race = 1 if asian == 1

rename born born_again
gen born_again_x = 0
replace born_again_x=. if born_again == "Don't know?/Refused"
replace born_again_x=0 if born_again== "NA"
replace born_again_x=0 if born_again=="No"
replace born_again_x=1 if born_again=="Yes"
tab born_again_x

encode religion, generate(religion_x)
gen jewish=0
replace jewish=1 if religion=="Jewish (Judaism)"

gen catholic=0
replace catholic=1 if religion=="Roman Catholic (Catholic)"

gen mormon=0
binreplace mormon=1 if religion=="Mormon (Church of Jesus Christ of Latter-day Saints/LDS)"

gen other_religion=0
replace other_religion=1 if religion=="Buddhist"
replace other_religion=1 if religion=="Hindu"
replace other_religion=1 if religion=="Muslim (Islam)"
replace other_religion=1 if religion=="Orthodox (Greek, Russian, or some other orthodox church)"
replace other_religion=1 if religion=="Unitarian (Universalist)"

gen secular_new = 0
replace secular_new=1 if religion_x== 1
replace secular_new=1 if religion_x== 2
replace secular_new=1 if religion_x== 4
replace secular_new=1 if religion_x== 10
tab secular_new

gen mainline_protstant_new=0
replace mainline_protstant_new=1 if religion_x==12 & born_again_x==0 & black==0
replace mainline_protstant_new=1 if religion_x==7 & black==0 & born_again_x==0
tab mainline_protstant_new
rename mainline_protstant_new mainline_protestant_new

gen evangelical_new=0
replace evangelical_new=1 if religion_x==7 &born_again_x==1 & black==0
tab evangelical_new
replace evangelical_new=1 if religion_x==12 & born_again_x==1 &black==0
tab evangelical_new

gen black_protestant_new=0
replace black_protestant_new=1 if religion_x==7 & black==1
replace black_protestant_new=1 if religion_x==12 & black==1
tab black_protestant_new

gen reltrad=.
replace reltrad=1 if secular_new==1
replace reltrad=2 if other_religion==1
replace reltrad=3 if jewish==1
replace reltrad=4 if catholic==1
replace reltrad=5 if mormon==1
replace reltrad=6 if mainline_protestant_new==1
replace reltrad=7 if evangelical_new==1
replace reltrad=8 if black_protestant_new==1
tab reltrad



